package myJs.api

import myJs.myPkg.MyFetch
import upickle.default._
import org.scalajs.macrotaskexecutor.MacrotaskExecutor.Implicits._
import shared.Pojo.PreprocessSoftData
import shared.pojo.Pojo.ValidData
import shared.tool.DefaultPickle
import myJs.Implicits._

/**
 * Created by yz on 18/10/2022
 */
object Soft {

  import shared.pojo.Pojo.soft._

  val baseUrl = s"${Api.apiUrl}/user/soft"

  val toIndex=s"${baseUrl}/toIndex"

  def video(fileName:String)=s"${baseUrl}/video?fileName=${fileName.encodeURI}"

  def checkFileName(request: CheckFileName.Request) = {
    val url = s"${baseUrl}/checkFileName"
    MyFetch.postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json")).map { str =>
      read[ValidData](str)
    }
  }

  def analysis(request: String) = {
    val url = s"${baseUrl}/analysis"
    MyFetch.postRnText(url = s"${url}", data = request, headers = Map("Content-Type" -> "application/json")).map { str =>
      read[ValidData](str)
    }
  }

}
